package br.com.trophy.games;

import java.util.Vector;
import br.com.trophy.parsing.Game;
import br.com.trophy.parsing.ParsingGames;
import android.R;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MyGames extends ListActivity
{
	// ----------------------------------------------------------------------
	// Atributos de classe
	// ----------------------------------------------------------------------
	private String[] values;

	private Intent i;
	private ArrayAdapter<String> adapter;
	private String user;
	private Vector<Game> games;
	private int indice;

	// ----------------------------------------------------------------------
	// Metodos Sobrecarregados
	// ----------------------------------------------------------------------
	@Override
	public void onCreate( Bundle bundle )
	{
		super.onCreate( bundle );
		// manager = new DataBaseManager( this );
		setAdapter();
		i = new Intent( this, GameView.class );
	}
	// ----------------------------------------------------------------------
	@Override
	public void onListItemClick( ListView l, View v, int position, long id )
	{
		super.onListItemClick( l, v, position, id );

		//bean = manager.selectGameById( position );
		indice = position;

		putExtras();
		startActivity( i );
	}
	// ----------------------------------------------------------------------
	// Metodos Publicos
	// ----------------------------------------------------------------------
	public void setAdapter()
	{
		user = "arleudo";
		games = ParsingGames.getGamesByUser( user );

		if ( games.size() > 0 )
		{
			values = new String[games.size()];

			for ( int i = 0; i < values.length; i++ )
			{
				values[i] = games.get( i ).getName();
			}

			adapter = new ArrayAdapter<String>( this,
					R.layout.simple_list_item_1, values );
			setListAdapter( adapter );
		}
		else
		{
			Toast.makeText( this, "Nenhum jogo cadastrado em sua conta", Toast.LENGTH_LONG ).show();
		}
	}
	// ----------------------------------------------------------------------
	// Metodos privados
	// ----------------------------------------------------------------------
	private void putExtras()
	{
		i.putExtra( "game", games.get( indice ));
	}
}
